package com.example.mymatch.service.Imp;

import com.example.mymatch.dao.IPower;
import com.example.mymatch.model.Power;
import com.example.mymatch.service.IPowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对服务接口规范的方法实现
 * 编写者：吴茂景
 */
@Service
public class IPowerServiceImpl implements IPowerService {

    @Autowired
    private IPower powerMapper;   //对后端数据操作某张表的定义规范 编写者：吴茂景

    @Override//添加方法
    public int insertPower(Power power){
        int powerValue=0;
        //查看当前菜单名称不能重复
        Power power1=new Power();
        power1.setId(power.getId());
        List<Power> getI=powerMapper.getAllPower(power1);
        if (getI.size()>0){
            //不可以添加菜单名称
            powerValue=-1;
        }else {
            powerValue=powerMapper.insertPower(power);
        }
        return powerValue;
    }

    @Override
    public List<Power> getAllPower(Power power){
        return powerMapper.getAllPower(power);
    }

    @Override
    public int updatePower(Power power){
        int powerValue=0;
        //判断主键不能为0
        if (power.getId()!=0){
            //主键信息必修存在

            //名称不能重复

            powerValue=powerMapper.updatePower(power);
        }
        return powerValue;
    }

    @Override
    public  int deletePower(Power power){
        int powerValue=0;
        //判断主键不能为0
        if (power.getPowerUserid()!=0){
            //主键是否有其他表有关联，如果关联，则先删除其他表的信息，或者给出此条信息不允许被删除


            powerValue=powerMapper.deletePower(power);
        }
        return powerValue;
    }

    //单条查询
    @Override
    public Power getPower(Power power){
        Power power1=new Power();
        if (power.getPowerUserid()!=0){
            power1=powerMapper.getPower(power);
        }
        return power1;
    }
}
